<template>
	<view class="page">
		<u-swiper :list="details.covers" :border-radius="0" name="fileUrl" :height="500" img-mode="aspectFit"></u-swiper>
		<view class="content-box">
			<view class="name">{{details.goodsName}}</view>
			<view class="price">¥ {{details.price}}</view>
			<view class="content">{{details.content}}</view>
			<view class="title">
				商品参数
			</view>
			<view class="imgList">
				<image class="img" v-for="(item,index) in details.goodsDataImgs" :key="index" :src="item.fileUrl" mode="widthFix"></image>
			</view>
		</view>
		<uni-popup ref="share" type="share"  safeArea backgroundColor="#fff">
			<view class="shareBox">
				<view class="shareDiv s-flex-c-c-c" @click="wxShare">
					<text>分享给微信好友</text>
				</view>
				<view class="shareDiv s-flex-c-c-c" @click="shareLink">
					<text>分享链接</text>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	import baseconfig from "@/common/baseconfig.js"
	export default {
		data() {
			return {
				details: {},
				id: ""
			}
		},
		onLoad(e) {
			if (e && e.id) {
				this.id=e.id
				this.getDetails()

			}
		},
		onNavigationBarButtonTap() {
			this.$refs.share.open()
		},
		methods: {
			shareLink(){
				let that=this
				const url = baseconfig.h5Url+`/h5/#/pages/index/shopDetails?id=${this.id}`
				uni.setClipboardData({
					data: url,
					showToast:false,
					success: function() {
						uni.showToast({
							icon: 'none',
							title: '链接已复制，请在浏览器中打开'
						})
					}
				});
			},
			//分享
			wxShare(){
				const url = baseconfig.h5Url+`/h5/#/pages/index/shopDetails?id=${this.id}`
				uni.share({
					provider: "weixin",
					scene: 'WXSceneSession',
					type: 0,
					title:'小泰助手',
					href: url,
					success: function (res) {
						uni.showToast({
							icon: 'none',
							title: '分享成功'
						})
					},
					fail: function (err) {
						console.log("fail:" + JSON.stringify(err));
					}
				})
			},
			getDetails() {
				this.httpClient.post('agents/app/shopping/getGoodsId', {
					goodsId: this.id
				}).then(res => {
					this.details = res.data
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.content-box {
		padding: 20rpx;
		.name{
			font-weight: bold;
			font-size: 34rpx;
			line-height: 46rpx;
		}
		.price {
			margin-top: 6rpx;
			color: #f14444;
			font-weight: bold;
		}
		.content{
			margin-top: 20rpx;
			color: #909090;
			line-height: 40rpx;
		}
		.title{
			margin: 20rpx 0;
			font-size: 30rpx
		}
		.imgList{
			width: 100%;
			.img{
				width: 100%;
			}
		}
	}
	.shareBox{
		padding:80rpx 30rpx;
		overflow: hidden;
		.shareDiv{
			height: 80rpx;
			border-bottom: 1rpx solid #eee;
		}
	}
</style>